<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入 
* G6 (https://github.com/antvis/G6)
*********************************************************************-->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <title data-i18n="resources.title_l7_map_interaction"></title>
    <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
    <style>
      body {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100vh;
        overflow: hidden;
      }
      #map {
        width: 100%;
        height: 100%;
      }
    </style>
  </head>

  <body>
    <div id="map"></div>
    <script type="text/javascript" include="mapbox-gl-enhance,L7,g2" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
    <script type="text/javascript">
      var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
      var attribution =
        "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
        " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
        " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";

      var map = new mapboxgl.Map({
        container: 'map',
        style: {
          version: 8,
          sources: {
            'raster-tiles': {
              attribution: attribution,
              type: 'raster',
              tiles: [
                host +
                  '/iserver/services/map-china/rest/maps/China/zxyTileImage.png?prjCoordSys=' +
                  encodeURIComponent('{"epsgCode":3857}') +
                  '&z={z}&x={x}&y={y}'
              ],
              tileSize: 256
            }
          },
          layers: [
            {
              id: 'simple-tiles',
              type: 'raster',
              source: 'raster-tiles',
              minzoom: 0,
              maxzoom: 22
            }
          ]
        },
        center: [-96, 37.8],
        zoom: 3
      });

      map.on('load', function () {
        map.getL7Scene().then((scene) => {
          fetch('https://iclient.supermap.io/web/data/L7/d36ad90e-3902-4742-b8a2-d93f7e5dafa2.json')
            .then((res) => res.json())
            .then((data) => {
              const color = [
                'rgb(255,255,217)',
                'rgb(237,248,177)',
                'rgb(199,233,180)',
                'rgb(127,205,187)',
                'rgb(65,182,196)',
                'rgb(29,145,192)',
                'rgb(34,94,168)',
                'rgb(12,44,132)'
              ];
              var layer = new mapboxgl.supermap.L7Layer({ type: 'PolygonLayer' });
              layer
                .getL7Layer()
                .source(data)
                .scale('density', {
                  type: 'quantile'
                })
                .color('density', color)
                .shape('fill')
                .active(true);
              map.addLayer(layer);

              var layer2 = new mapboxgl.supermap.L7Layer({ type: 'LineLayer' });
              layer2
                .getL7Layer()
                .source(data)
                .color('#fff')
                .active(true)
                .size(1)
                .style({
                  lineType: 'dash',
                  dashArray: [2, 2]
                });
              map.addLayer(layer2);
              layer.getL7Layer().on('mousemove', (e) => {
                const popup = new L7.Popup({
                  offsets: [0, 0],
                  closeButton: false
                })
                  .setLnglat(e.lngLat)
                  .setHTML(`<span>${e.feature.properties.name}: ${e.feature.properties.density}</span>`);
                scene.addPopup(popup);
              });
            });
        });
      });
    </script>
  </body>
</html>
